/**
 * Created by Money on 2017/12/3 0003.
 */


$(function () {
    $(".goods").each(function (i, ele) {
        $("." + this.id).click(function () {
            ele.title = this.title;
            var t = $("#c" + ele.id);
            t.text(this.title + "份");
            var a = $("#" + ele.id);
            var rid = $("#rid").val();
            $.getJSON("order?rid=" + rid + "&gid=" + i + "&count=" + this.title, function (result) {
                console.log(result["GoodsList"][i]);
                if (result["GoodsList"][i]["Count"] > 0) {
                    a.removeClass("btn-default");
                    a.addClass("btn-info");
                } else {
                    a.addClass("btn-default");
                    a.removeClass("btn-info");
                }
            })
        });

        this.onclick = function () {
            var a = $("#" + ele.id);
            var rid = $("#rid").val();
            $.getJSON("order?rid=" + rid + "&gid=" + i + "&count=" + this.title, function (result) {
                console.log(result["GoodsList"][i]);
                if (result["GoodsList"][i]["Count"] > 0) {
                    a.removeClass("btn-default");
                    a.addClass("btn-info");
                } else {
                    a.addClass("btn-default");
                    a.removeClass("btn-info");
                }
            })
        }
    })
});

$(function () {
    $("#cancelList").click(function () {
        $("#warning").removeClass("modal");
        $("#warning").addClass("modal-open")
    })
});


$(function () {
    $("#cancel_sure").click(function () {
        var rid = $("#rid").val();
        $.getJSON("payment?rid=" + rid + "&order=cancel", function (result) {
            if (result["error"] === "") {
                window.location.href = "business"
            }
        })
    })
});

$(function () {
    $("#cancel_wrong").click(function () {
        $("#warning").removeClass("modal-open");
        $("#warning").addClass("modal")
    })
});